﻿using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TR.AppService.Dto;
using TR.AppService.Dto.BSDto;
using TR.Domain.Entity;
using TR.Domain.Entity.BsItemType;
using TR.Domain.Repository.BS_Item_TypeRepository;
using TR.Domain.Repository.BSType;
using TR.Domain.Repository.Sys_EncodeRepository;

namespace TR.AppService.AppService.BS
{
    public class BsItemTypeService : IBsItemTypeService
    {
        private readonly IBsItemTypeRepository itemTypeRepository;
        private readonly IMapper mapper;
        public BsItemTypeService(IBsItemTypeRepository itemTypeService, IMapper mapper)
        {
            this.itemTypeRepository = itemTypeService;
            this.mapper = mapper;
        }
        //分页查询
        public async Task<DtoFenYe<bs_Item_Type>> bs_ItemType_FenYe(int pageSize, int currentPage, string kssj,string jssj,BSFenYeTjDto bft)
        {
            bs_Item_Type bit = mapper.Map<bs_Item_Type>(bft);
            var lissFenYe = await itemTypeRepository.bs_ItemType_FenYeAsync(pageSize, currentPage, kssj,jssj, bit);
            var zs = await itemTypeRepository.count();
            var result = new DtoFenYe<bs_Item_Type>()
            {
                mys = pageSize,
                dqy = currentPage,
                list = lissFenYe,
                zts = zs
            };

            return result;
        }

        public  Task<bool> ItemtypeAdd(AddItemTypeDto addItemTypeDto)
        {
            bs_Item_Type bs = mapper.Map<bs_Item_Type>(addItemTypeDto);
            return itemTypeRepository.ItemTypeAdd(bs);
        }
        public async Task<bool> ItemtypeUDelect(string area_code)
        {
            return await itemTypeRepository.ItemtypeUDelect(area_code);
        }
        public Task<bool> ItemTypeUpdate(UpdateItemTypeDto usd)
        {
            return itemTypeRepository.ItemTypeUpdate(usd);
        }
        /// <summary>
        /// 查询id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Task<bs_Item_Type> ItemTypeSelectid(int id)
        {
            return itemTypeRepository.ItemTypeSelectid(id);
        }
    }
}
